package com.ansion.utils.permission;


import androidx.annotation.NonNull;


public abstract class Permission {

    public static Permission granted(final String name) {
        return new AutoValue_Permission(name, State.GRANTED);
    }

    public static Permission denied(final String name) {
        return new AutoValue_Permission(name, State.DENIED);
    }

    public static Permission deniedNotShown(final String name) {
        return new AutoValue_Permission(name, State.DENIED_NOT_SHOWN);
    }

    public static Permission revokedByPolicy(final String name) {
        return new AutoValue_Permission(name, State.REVOKED_BY_POLICY);
    }

    @NonNull
    public abstract String name();

    /**
     * The state of the permission.
     */
    @NonNull
    public abstract State state();

    public boolean isGranted(){
        return state() == State.GRANTED;
    }

    public enum State {
        /**
         * Permission has been granted.
         */
        GRANTED,

        /**
         * Permission has been denied.
         */
        DENIED,

        /**
         * Permission is denied.
         * Previously the requested permission was denied and never ask again was selected.
         * This means that the user hasn't seen the permission dialog.
         * The only way to let the user grant the permission is via the settings now.
         */
        DENIED_NOT_SHOWN,

        /**
         * Permission has been revoked by a policy.
         */
        REVOKED_BY_POLICY
    }
}
